//nested.cpp -- using a queue that has a nested class
//rtti2.cpp -- using dynamic_cast, typeid, and type_info
#include <iostream>

#include <string>
#include "chapter15_queuetp.h"

#include "chapter15_error5.h";

#include "chapter15_rtti1.h"

#include <typeinfo>

void Example_15_6();
void Example_15_12();
void Example_15_17();
void Example_15_18();

//int main()
//{
//	Example_15_18();
//	return 0;
//}

void Example_15_6()
{
	using namespace std;
	QueueTP<string> cs(5);
	string temp;

	while (!cs.isfull())
	{
		cout << "Please enter your name.You will be "
			<< "served in the order of arrival.\n"
			<< "name: ";
		getline(cin, temp);
		cs.enqueue(temp);
	}
	cout << "The queue is full. Processing begin!\n";

	while (!cs.isempty())
	{
		cs.dequeue(temp);
		cout << "Now processing " << temp << "...\n";
	}
	return;
}

void Example_15_12()
{
	using namespace std;
	double x, y, z;
	{
		demo d1("found in block in main()");
		cout << "Enter two numbers: ";
		while (cin >> x >> y)
		{
			try{					//strat of try block
				z = means(x, y);
				cout << "The mean mean of " << x << " and " << y
					<< " is " << z << endl;
				cout << "Enter next pair: ";
			}
			catch(bad_hmean & bg)		//start of catch block
			{
				bg.mesg();
				cout << "Try again.\n";
				continue;
			}
			catch (bad_gmean & hg)
			{
				cout << hg.mesg();
				cout << "Values used: " << hg.v1 << ", " << hg.v2 << endl;
				cout << "Sorry, you don't get to play any more.\n";
				break;
			}//end of catch block
		}
		d1.show();
	}
	cout << "Bye!\n";
	cin.get();
	cin.get();
	return;
}

void Example_15_17()
{
	using namespace std;
	srand(time(0));
	Grand * pg;
	Superb * ps;
	for (int i = 0; i < 5; i++)
	{
		pg = GetOne();
		pg->Speak();
		if (ps = dynamic_cast<Superb *>(pg))
			ps->Say();
	}
	return;
}

void Example_15_18()
{
	using namespace std;
	srand(time(0));
	Grand * pg;
	Superb * ps;
	for (int i = 0; i < 5; i++)
	{
		pg = GetOne();
		cout << "Now processing type " << typeid(*pg).name() << ".\n";
		pg->Speak();
		if (ps = dynamic_cast<Superb *>(pg))
			ps->Say();
		if (typeid(Magnificent) == typeid(*pg))
			cout << "Yes, you're really magnigicent.\n";
	}
	return;
}